﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace PizzaService.BindValidation
{

    /// <summary>
    /// PLZ
    /// </summary>
    class ValidatePLZ : ValidationRule
    {
        private int maxLength = 5;

        /// <summary>
        /// Validate the postal code
        /// </summary>
        /// <param name="value"></param>
        /// <param name="cultureInfo"></param>
        /// <returns></returns>
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            string tempS = (string)value;

            if (tempS.Length > maxLength)
                return new ValidationResult(false, "Bitte eine gültige Postleitzahl eingeben");

            foreach (char c in tempS)
            {
                if (!Char.IsDigit(c))
                    return new ValidationResult(false, "Postleitzahlen bestehen nur aus Ziffern");
            }

            return ValidationResult.ValidResult;
	{
		 
	}
        }
    }
}
